package behavioral.command.dataProc.cmds;

import behavioral.command.dataProc.Command;
import behavioral.command.dataProc.objs.Author;
import behavioral.command.dataProc.objs.NetPaper;

/**
 * 论文作者处理
 */
public class PaperAuthorCmd implements Command {
    NetPaper netPaper;

    public PaperAuthorCmd(NetPaper netPaper) {
        this.netPaper = netPaper;
    }


    @Override
    public void execute() {
        if (netPaper.getAuthor() != null) {
            String[] authors = netPaper.getAuthor().split(",");
            for (int i = 0; i < authors.length; i++) {
                String author = authors[i].trim();
                Author auth = new Author();
                auth.setOrder(i + 1);
                if (author.indexOf("*") != -1) {
                    auth.setRole("通讯作者");
                    author = author.replace("*", "");
                } else {
                    auth.setRole("作者");
                }
                auth.setName(author);
                netPaper.getPaper().getAuthors().add(auth);
            }
        }
    }
}
